using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace Ketoan
{
	/// <summary>
	/// Summary description for Print_kt.
	/// </summary>
	public class Print_kt
	{
		public Print_kt(){}
		public string Printer(LibKetoan.AccessData a,DataSet ds_Data,string s_Tenbaocao,string s_Ngaythang,string s_Tinhchat,string s_Giatri11,string s_Giatri12,string s_Giatri21,string s_Giatri22,string s_Giatri31,string s_Giatri32,string s_Giatri41,string s_Giatri42,string s_Giatri51,string s_Giatri52,string s_Report,string s_Pagesize,int i_Kieu,int i_Copy)
		{
			try
			{
				ReportDocument oRpt=new ReportDocument();
				oRpt.Load("..\\..\\..\\report\\"+s_Report,OpenReportMethod.OpenReportByTempCopy);
				oRpt.SetDataSource(ds_Data);
				oRpt.DataDefinition.FormulaFields["SoYTe"].Text="'"+a.Syte+"'";
				oRpt.DataDefinition.FormulaFields["BenhVien"].Text="'"+a.Tenbv+"'";
				oRpt.DataDefinition.FormulaFields["Tenbaocao"].Text="'"+s_Tenbaocao+"'";
				oRpt.DataDefinition.FormulaFields["Ngaythang"].Text="'"+s_Ngaythang+"'";
				oRpt.DataDefinition.FormulaFields["Tinhchat"].Text="'"+s_Tinhchat+"'";
				oRpt.DataDefinition.FormulaFields["Giatri11"].Text="'"+s_Giatri11+"'";
				oRpt.DataDefinition.FormulaFields["Giatri12"].Text="'"+s_Giatri12+"'";
				oRpt.DataDefinition.FormulaFields["Giatri21"].Text="'"+s_Giatri21+"'";
				oRpt.DataDefinition.FormulaFields["Giatri22"].Text="'"+s_Giatri22+"'";
				oRpt.DataDefinition.FormulaFields["Giatri31"].Text="'"+s_Giatri31+"'";
				oRpt.DataDefinition.FormulaFields["Giatri32"].Text="'"+s_Giatri32+"'";
				oRpt.DataDefinition.FormulaFields["Giatri41"].Text="'"+s_Giatri41+"'";
				oRpt.DataDefinition.FormulaFields["Giatri42"].Text="'"+s_Giatri42+"'";
				oRpt.DataDefinition.FormulaFields["Giatri51"].Text="'"+s_Giatri51+"'";
				oRpt.DataDefinition.FormulaFields["Giatri52"].Text="'"+s_Giatri52+"'";
				//Chon kho giay in
				switch (s_Pagesize)
				{
					case "A3": 
						oRpt.PrintOptions.PaperSize=PaperSize.PaperA3;
						break;
					case "A4": 
						oRpt.PrintOptions.PaperSize=PaperSize.PaperA4;
						break;
					case "A5": 
						oRpt.PrintOptions.PaperSize=PaperSize.PaperA5;
						break;
					default:
						oRpt.PrintOptions.PaperSize=PaperSize.DefaultPaperSize;
						break;
				}
				//i_Kieu=1 : in kho giay dung; i_Kieu<>1 : in kho giay ngang.
				oRpt.PrintOptions.PaperOrientation=(i_Kieu==1)?PaperOrientation.Portrait:PaperOrientation.Landscape;
				//if (mayin!="") oRpt.PrintOptions.PrinterName=mayin;
				oRpt.PrintToPrinter(i_Copy,false,0,0);
				return "";
			}
			catch(Exception ex)
			{
				//MessageBox.Show(ex.Message);
				return ex.Message.ToString();
			}
		}
	}
}
